﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Data.Common;
//using Jacaranda.Data;

//namespace Jacaranda.Model
//{
//    public class AssociationMatchCriteria : ConditionalExpression
//    {
//        public string Field { get; set; }

//        public object AssociationEntityKeyValue { get; set; }


//        internal override string GenerateSql()
//        {
//            FieldMetadata sourcePrimaryKey = Metadata.Type(EntityType).PrimaryKey;
//            Type targetType = Metadata.RegisteredTypes.First(i => i.Type.Name == Field).Type;

//            AssociationField field = Metadata.Type(EntityType).AssociationFields.First(i => i.From.Equals(EntityType) && i.To.Equals(targetType));

//            return string.Format("{0} IN (SELECT {1} FROM {2} WHERE {3}='{4}')",
//                sourcePrimaryKey.FieldName,
//                field.IsSourceToTargetOrder ? "Key1" : "Key2",
//                field.Association.TableName,
//                field.IsSourceToTargetOrder ? "Key2" : "Key1",
//                AssociationEntityKeyValue);
//        }
//    }
//}
